package test3;

public class GirlFriendTest {
    public static void main(String[] args) {
        //创建女朋友数组
        GirlFriend[] arr = new GirlFriend[3];
        //创建女朋友对象
        GirlFriend g1=new GirlFriend("梅菜扣肉饼",18,"蒸桑拿");
        GirlFriend g2=new GirlFriend("糖葫芦",19,"吃糖");
        GirlFriend g3=new GirlFriend("冰激凌",20,"探险南北极");
        //把对象放到数组中
        arr[0]=g1;
        arr[1]=g2;
        arr[2]=g3;
        //遍历数组，求和
        int sum=0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend girlFriend=arr[i];
            sum+=girlFriend.getAge();
        }
        //求平均值
        int average=0;
        int count=0;
        average=sum/arr.length;
        System.out.println(average);
        //遍历数组，找出年龄小于平均年龄的女朋友
        for (int i = 0; i < arr.length; i++) {
            GirlFriend girlFriend=arr[i];
            if(girlFriend.getAge()<=average){
                System.out.println(girlFriend.getName()+","+girlFriend.getAge()+","+girlFriend.getHobby());
                count++;
            }

        }
        System.out.println(count);
    }
}
